// 审核教学任务
<template>
  <div id="check-teaching-task-index">
    <div class="assessment-container">
      <div class="search-container">
        <div class="search-container-left" style="display: flex;
    align-items: center;">
          <div class="search-container-item">
            <span>学期：</span>
            <el-select
              v-model="xq"
              style="width: 85px"
              size="mini"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in xqList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <div class="search-container-item">
            <span>培养层次：</span>
            <el-select
              v-model="pycc"
              style="width: 85px"
              size="mini"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in pyccList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <div class="search-container-item">
            <span>级次：</span>
            <el-select
              v-model="jc"
              style="width: 85px"
              size="mini"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in jcList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <div class="search-container-item">
            <span>课程负责单位：</span>
            <el-popover
              trigger="click"
              placement="bottom"
              v-model="showUnitTree"
              style="cursor: pointer"
              width="120"
              clearable
            >
              <div style="max-height: 260px; overflow-y: auto">
                <el-tree
                  default-expand-all
                  node-key="id"
                  :data="bxList"
                  :expand-on-click-node="false"
                  :props="props"
                  @node-click="toShowUnitInfo"
                >
                </el-tree>
              </div>
              <el-input
                slot="reference"
                v-model="kcfzdw"
                class="selectTree"
                clearable
                style="width: 120px"
                suffix-icon="el-icon-arrow-down"
              >
              <!-- :readonly="true" -->
              </el-input>
            </el-popover>

            <!-- <el-select v-model="kcfzdw" style="width: 85px" size="mini" placeholder="请选择">
            <el-option v-for="item in kcfzdwList" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select> -->
          </div>
          <div class="search-container-item">
            <span>课程名称：</span>
            <el-input
              style="width: 120px"
              size="mini"
              placeholder="请输入内容"
              v-model="kcmc"
            ></el-input>
          </div>
          <div class="search-container-item">
            <span>状态：</span>
            <el-select
              v-model="zt"
              style="width: 85px"
              size="mini"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in ztList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </div>
          <div class="search-button" @click="shjxQueryList">
            <img
              src="../../../../../assets/assessment/icon-search.png"
              alt=""
            />
            <span>查询</span>
          </div>
        </div>
        <div class="search-container-right">
          <el-button
          v-if="role=='strator'"
            type="primary"
            size="mini"
            icon="el-icon-circle-check"
            plain
            @click="xfhd"
            >下发核对</el-button
          >
          <el-button
           v-if="role=='director'"
            type="warning"
            size="mini"
            icon="el-icon-upload2"
           plain
            @click="exportData"
            >导出教材信息</el-button
          >
          <el-button
           v-if="role=='strator' || role=='director'"
            type="primary"
            size="mini"
            icon="el-icon-circle-check"
           plain
            @click="shtg"
            >审核通过</el-button
          >
          <el-button
           v-if="role=='strator' || role=='director'"
            type="danger"
            size="mini"
            icon="el-icon-circle-close"
           plain
            @click="taskBack"
            >打回</el-button
          >
        </div>
      </div>
    </div>

    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          style="width: 100%; height: calc(100vh - 400px);overflow: auto;"
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          @selection-change="handleSelectionChange"
        >
          <el-table-column width="100" align="center" type="selection">
          </el-table-column>
          <el-table-column
            prop="fzdw"
            label="系"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jys"
            label="教研室"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="kcbh"
            label="课程编号"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="kcmc"
            label="课程名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="courseCharger"
            label="课程负责人"
            align="center"
          >
            <template slot-scope="{ row, $index }" width="100">
              <div v-if="roleId == '1475294432243830786'">{{ row.courseCharger}}</div>
              <div v-else><span>{{ row.courseCharger}}
                <img
                  v-if="row.state !='已审核'"
                  @click="selectCourseCharge($index)"
                  src="../../../../../assets/assessment/icon-plan-record-detail.png"
                  width="20"
                  height="20"
                /></span></div>
            </template>
          </el-table-column>
          <el-table-column
            prop="xs"
            label="总学时"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jxbList"
            label="教学班信息"
            width="300"
            align="center"
          >
            <template slot-scope="{ row }">
              <div v-for="(item, index) in row['jxbList']" :key="index">
                <span @click="viewJXBXX(item.id)" class="undeLine">{{ item.name }}</span>
                【<span v-for="data in item.zybcList"
                  >{{ data.name }}(<span style="color:red; cursor:pointer;"  @click="showDetailBtn(row, data)">{{ data.yxrs }}</span>)人，</span
                >】
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="zybcList"
            label="未安排专业班次"
            align="center"
          >
            <template slot-scope="{ row }">
              <span v-for="(item, index) in row['zybcList']" :key="index">
                <span v-if="item.wxrs != '0'">
                  {{ item.name }}({{item.wxrs}})人，
                </span>
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="jcmc" label="教材" align="center">
            <template slot-scope="{ row, $index }" width="100">
              <div v-if="row.cgfs == '0'">
                <span>不需要教材<img
                    v-if="row.state != '审核通过' || row.state != '已发布'"
                    @click="viewJCXX(row)"
                    src="../../../../../assets/assessment/icon-plan-record-detail.png"
                    width="20"
                    height="20"
                  /></span>
              </div>
              <div v-else>
                <div v-if="row.jcid != ''"><span>{{ row.jcmc
                }}<img
                    v-if="row.state != '审核通过' || row.state != '已发布'"
                    @click="viewJCXX(row)"
                    src="../../../../../assets/assessment/icon-plan-record-detail.png"
                    width="20"
                    height="20"
                  /></span></div>
                <el-button
                  style="width: 100%;"
                  v-if="row.jcid ==''"
                  type="warning"
                  size="mini"
                  plain
                  icon="el-icon-circle-plus-outline"
                  @click="tianjiaJiaoCai(row)"
                >添加</el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="state"
            label="状态"
            align="center"
          ></el-table-column>
          <el-table-column prop="remark" label="备注" align="center">
            <template slot-scope="scoped">
              <div>
                {{scoped.row.remark}}
              </div>
              <div>
                <img
                  src="../../../../../assets/assessment/icon-plan-record-detail.png"
                  width="20"
                  height="20"
                  @click="addRemarks(scoped.row)"
                />
              </div>
            </template>
          </el-table-column>
          <el-table-column
          v-if="role!='teacher'"
            prop="fillby"
            label="最后修改"
            width="300"
            align="center"
          >
            <template slot-scope="scoped">
              <span class="undeLine" @click="viewLastEdit(scoped.row)">{{
                scoped.row["fillbyName"]
              }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="wrapper-container" style="width:100%">
      <div class="bottom-block" style="display: block">
        <div class="text">
          当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条
        </div>
      </div>
      <div class="export-button" style="margin-left: 10px;" @click="exportData">
        <img src="../../../../../assets/assessment/icon-export.png" alt="" />
        <span>&ensp;导出Excel</span>
        <!-- <download-excel
          class="export-btn"
          :data="tableData"
          :fields="jsonFields"
          type="xls"
          name="审核教学任务.xls"
          style="color: #f3b815"
        >
        </download-excel> -->
      </div>
      <div class="pagination-block">
        <el-pagination
          prev-text="上一页"
          next-text="下一页"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </div>
    </div>

    <el-row
      style="
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 30px;
      "
    >
      <el-button type="warning" v-if="role=='strator'" size="mini" plain @click="fabu">发布</el-button>
    </el-row>

    <el-dialog
      title="教学任务打回原因"
      :visible.sync="taskBackDialog"
      width="600px"
      class="remarks"
    >
      <el-row>
        <el-col :span="4" :offset="2"
          ><div style="color: #004ca7; font-size: 16px; font-weight: bold">
            打回原因：
          </div></el-col
        >
        <el-col :span="16"
          ><el-input type="textarea" rows="5" v-model="backReason"></el-input
        ></el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="warning"
          size="mini"
          style="margin-right: 50px"
          @click="submitTaskBack()"
          >确 定</el-button
        >
        <el-button type="danger" size="mini" @click="cancelTaskBack()"
          >取 消</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="备注"
      :visible.sync="remarksDialog"
      width="600px"
      class="remarks"
    >
      <el-row>
        <el-col :span="4" :offset="2"
          ><div style="color: #004ca7; font-size: 16px; font-weight: bold">
            备注：
          </div></el-col
        >
        <el-col :span="16"
          ><el-input type="textarea" rows="5" v-model="remarks_fill"></el-input
        ></el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="warning"
          plain
          style="margin-right: 50px"
          @click="submitRemarks()"
          >确 定</el-button
        >
        <el-button type="danger" plain @click="cancelRemarkDialog()"
          >取 消</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="课程负责人设置"
      :visible.sync="showSpeakerDialog"
      width="1400px"
      style="border: 0px; height: auto"
      class="jxkzj"
    >
      <div>
        <el-row>
          <el-col :span="4">
            <el-tree
              default-expand-all
              :data="data"
              :props="defaultProps"
              @node-click="handleNodeClick"
              style="
                color: #004ca7;
                margin: 20px 40px;
                font-weight: bold;
                background: #f0f2f5;
              "
            ></el-tree>
          </el-col>
          <el-col :span="20" class="border-left">
            <div
              class="assessment-container"
              style="
                width: 100%;
                padding: 20px;
                border-left: 1px solid #004ca7;
                pading-left: 0px;
              "
            >
              <div class="search-container">
                <div class="search-container-left">
                  <div class="search-container-item">
                    <el-input
                      placeholder="关键字搜索"
                      style="width: 100%"
                      size="small"
                      v-model="queryKey"
                    ></el-input>
                  </div>
                  <div class="search-button" @click="queryTeacherInfo()" style="margin-top: 5px;">
                    <img
                      src="../../../../../assets/assessment/icon-search.png"
                      alt=""
                    />
                    <span>查询</span>
                  </div>
                </div>
              </div>
              <!--<div class="search-container">-->
                <!--<div class="search-container-left">-->
                  <!--<div-->
                    <!--class="search-container-item"-->
                    <!--style="-->
                      <!--margin: 5px 0;-->
                      <!--width: 100%;-->
                      <!--overflow: auto;-->
                      <!--height: 25px;-->
                    <!--"-->
                  <!--&gt;-->
                    <!--&lt;!&ndash;<span>已选人员:</span>&ndash;&gt;-->
                    <!--&lt;!&ndash;<el-tag&ndash;&gt;-->
                      <!--&lt;!&ndash;size="small"&ndash;&gt;-->
                      <!--&lt;!&ndash;v-for="(tag, inx) in selectCourseChargeList"&ndash;&gt;-->
                      <!--&lt;!&ndash;:key="tag.xm"&ndash;&gt;-->
                      <!--&lt;!&ndash;closable&ndash;&gt;-->
                      <!--&lt;!&ndash;type="info"&ndash;&gt;-->
                      <!--&lt;!&ndash;hit&ndash;&gt;-->
                      <!--&lt;!&ndash;@close="handleClose(tag, inx)"&ndash;&gt;-->
                    <!--&lt;!&ndash;&gt;&ndash;&gt;-->
                      <!--&lt;!&ndash;{{ tag.xm }}&ndash;&gt;-->
                    <!--&lt;!&ndash;</el-tag>&ndash;&gt;-->
                  <!--</div>-->
                <!--</div>-->
              <!--</div>-->
              <div class="table-container" style="width: 100%; border: 0px">
                <el-table
                  ref="multipleTable"
                  :data="speakerTableData"
                  border
                  class="table-data"
                  row-class-name="row-class"
                  cell-class-name="cell-class"
                  header-row-class-name="header-row-class"
                  header-cell-class-name="header-cell-class"
                  style="height: 330px; overflow-y: auto"
                  @selection-change="handleSelectionChange01"
                >
                  <el-table-column
                    align="center"
                    type="selection"
                    width="80"
                  ></el-table-column>
                  <el-table-column
                    prop="gzbm"
                    label="教研室"
                    align="center"
                  ></el-table-column>
                  <el-table-column
                    prop="xm"
                    label="姓名"
                    align="center"
                  ></el-table-column>
                </el-table>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="warning"
          size="mini"
          plain
          style="margin-right: 50px"
          @click="submitSelectTeacher()"
        >确 定</el-button
        >
        <el-button type="danger" size="mini" plain @click="cancelSelect"
        >取 消</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      :title="rowTitle"
      :visible.sync="showDetailDialog"
      width="60%"
      class="xzjy"
    >
      <div
        style="display: flex; flex-direction: column"
      >
        <div class="assessment-container" style="margin: 0px">
          <div class="table-container" style="border: 0px solid #004ca7">
            <el-table
              ref="multipleTable"
              :data="tableData2"
              border
              class="table-data"
              row-class-name="row-class"
              cell-class-name="cell-class"
              header-row-class-name="header-row-class"
              header-cell-class-name="header-cell-class"
              style="height: 400px; overflow-y: auto; width: 100%;"
            >
              <el-table-column
                align="center"
                type="selection"
                width="80"
              ></el-table-column>
              <el-table-column
                prop="studentCode"
                label="学号"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="studentName"
                label="姓名"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="gender"
                label="性别"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="birthday"
                label="出生日期"
                align="center"
              ></el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  shjx_query_list,
  jxbgl_data_remark,
  jxbgl_data_dh,
  queryCommonPyccId,
  queryCommonNj,
  queryCommonXueqi,
  queryCommonJysDept,
  bpksj_query_edu_sh,
  bpksj_query_edu_tg,
  queryCommonShzt,
  jxbgl_data_fb,
  shjx_query_exportSh,
  jxbgl_query_teacher_list,
  queryCommonDeptByCategory,
  queryDefaultXueQi,
  updateCourseCharger,
  jxbgl_query_student_list
} from "@/api/trainingManagement/place.js";
import { createDataForCourse } from '@/api/course/courses'
import { getStore } from "@/util/store.js"
export default {
  data() {
    return {
      roleId: '',
      data: [], //部门树列表
      speakerTableData: [], //讲师表格数据
      showSpeakerDialog: false,
      selectCourseChargeIndex: 0,
      selectCourseChargeList:[],
      jxkZhujiang: [], //教学课主讲
      queryKey: "", //搜索关键字
      selectTreeNode: {}, //点击树节点
      bxList: [], //部系列表
      props: {
        children: "children",
        label: "name",
      },
      defaultProps: {
        children: "children",
        label: "name",
      },
      showUnitTree: false,

      fzdw: '',
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
      jsonFields: {
        专业班次: "specialtyName",
        年级: "year",
        专业: "className",
        门数: "coursrCount",
        状态: "state",
      },
      backReason: "", //打回原因
      remarks_fill: "", //备注
      remarksDialog: false, //备注弹窗
      taskBackDialog: false,
      xq: "",
      xqList: [],
      jc: "",
      jcList: [],
      zt: "",
      ztList: [
        {id:null, name:'全部'},
        {id:'待审核', name:'待审核'},
        {id:'审核通过', name:'审核通过'},
        {id:'已发布', name:'已发布'},
        {id:'打回', name:'打回'},
      ],
      kcfzdw: "",
      kcfzdwList: [],
      kcmc: "",
      pycc: "",
      pyccList: [],
      research: "",
      researchList: [],
      tableData: [],
      selectRow: {}, //当前行信息
      xiId: "", //部系id
      selectPlanList: [],
      userInfo: {}, //当前登陆人信息
      role: "", //登陆人角色

      rowTitle:'',
      showDetailDialog: false,
      tableData2:[],
    };
  },
  created() {

  },
  mounted() {
    const userInfo = getStore({
      name: "userInfo",
      debug: true,
    }) || {}
    console.log('--------------------------', userInfo)
    this.userInfo = userInfo;
    this.roleId = userInfo.content.role_id
    this.role = userInfo.content.role_name;
    // this.role = "director"
    this.queryCommonPycc();
    this.queryCommonNj();
    this.queryCommonXueqi();
    this.queryCommonDept();
    this.queryCommonShzt();
    // this.shjxQueryList();
    this.getDefaultXueQi();
  },
  methods: {
    handleSelectionChange01(val) {
      this.selectCourseChargeList = val;
    },
    // 选择讲师确定
    submitSelectTeacher() {
      if(this.selectCourseChargeList){
        if(this.selectCourseChargeList.length <= 0){
          this.showSpeakerDialog = false;
        }else{
          if(this.selectCourseChargeList.length > 1){
            this.$message.warning('最多只能选择一个课程负责人')
            return
          }
          this.tableData[this.selectCourseChargeIndex].courseCharger = this.selectCourseChargeList[0].xm;
          updateCourseCharger(this.tableData[this.selectCourseChargeIndex].jhCourseInfoId, this.selectCourseChargeList[0].xm).then(res=>{
            if(res.data.code == 200){
              this.getDefaultXueQi();
            }
          })
        }
        // 教学课主讲
        // this.jxkZhujiang = this.selectCourseChargeList;
        this.showSpeakerDialog = false;
      }else{
        this.$message.warning('最少要选择一个课程负责人')
      }
    },
    cancelSelect() {
      this.showSpeakerDialog = false;
      this.selectCourseChargeList = [];
      this.$refs.multipleTable.clearSelection(); // 取消选中
    },
    async queryCommonDept001() {
      const res = await queryCommonDeptByCategory(7);
      if (res.data.code == 200) {
        this.data = res.data.data;
        this.selectTreeNode = this.data[0];
        this.queryTeacherInfo();
      }
    },
    selectCourseCharge(index){
      this.selectCourseChargeIndex = index;
      this.showSpeakerDialog = true;
      this.queryCommonDept001();
    },
    // 点击树节点
    handleNodeClick(node) {
      this.selectTreeNode = node;
      this.queryTeacherInfo();
    },
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.xq = res.data.data
        }
      }).then(()=>{
        this.shjxQueryList()
      })
    },
    // 查询教师信息
    async queryTeacherInfo() {
      var _this = this;
      var GZBM = this.selectTreeNode.id;
      var keyWord = this.queryKey;
      const res = await jxbgl_query_teacher_list(GZBM, keyWord);
      if (res.data.code == 200) {
        _this.speakerTableData = res.data.data.records;
        // 教学课主讲
        _this.selectCourseChargeList = _this.jxkZhujiang;
        _this.speakerTableData.forEach((item) => {
          _this.jxkZhujiang.forEach((da) => {
            if (item.id == da.id) {
              _this.$refs.multipleTable.toggleRowSelection(item, true);
            }
          });
        });
      }
    },
    //查看教学班信息
    viewJXBXX(row) {
      console.log(row, "wwwwwwww")
        this.$router.push({
          path: "/admin/teachingTaskManage/teachingclass/viewClassInformation",
          query: {
            id: row
          }
        })
    },
    //添加教材
    tianjiaJiaoCai(row) {
      localStorage.removeItem('jcid');
      localStorage.removeItem('jcmc');
      localStorage.removeItem('bz');
      localStorage.removeItem('cbs');
      localStorage.removeItem('cbrq');
      var zybc = "";
      if (row.zybcList.length > 0) {
        row.zybcList.forEach(item => {
          zybc += item.name + "(" + item.rs + "), ";
        })
      }
      localStorage.setItem('kcbh', row.kcbh);
      localStorage.setItem('xueqi', row.xueqi);
      localStorage.setItem('courseId', row.kcid);
      this.$router.push({
        path: "/admin/teachingTaskManage/teachingclass/addTextbook",
        query: {
          id: row.id,
          grade: row.nj,
          professional: zybc,
          className: row.kcmc,
          classHours: row.xs,
          system: row.fzdw,
          teachingOffice: row.jys,
          courseId: row.kcid,
          kcbh: row.kcbh,
          xueqi: row.xueqi
        }
      })
    },
    // 查看教材
    viewJCXX(row) {
      localStorage.setItem('kcbh', row.kcbh);
      localStorage.setItem('xueqi', row.xueqi);
      localStorage.setItem('courseId', row.kcid);
      var zybc = "";
      if (row.zybcList.length > 0) {
        row.zybcList.forEach(item => {
          zybc += item.name + "(" + item.rs + "), ";
        })
      }
      this.$router.push({
        path: "/admin/teachingTaskManage/teachingclass/editTextbook",
        query: {
          id: row.id,
          grade: row.nj,
          professional: zybc,
          className: row.kcmc,
          classHours: row.xs,
          system: row.fzdw,
          teachingOffice: row.jys,
          courseId: row.kcid,
          kcbh: row.kcbh,
          xueqi: row.xueqi
        }
      })
    },
    // 导出教材信息
    exportData() {
      var term = this.xq;
      var xb = this.xiId;
      var courseName = this.kcmc;
      var pyLevel = this.pycc;
      var nj = this.jc;
      var status = this.zt;
      shjx_query_exportSh(term, xb, courseName, pyLevel, nj, status).then((res) => {
        /** 获取生成设置好的文件名 */
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "教学任务.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    // 获取部门
    async queryCommonDept() {
      const res = await queryCommonJysDept();
      if (res.data.code == 200) {
        this.bxList = res.data.data;
      }
    },
    toShowUnitInfo(data, node) {
      // if(node.level == 1){
      //   this.kcfzdw = data.name;
      //   this.xiId = data.id;
      //   this.jysId = "";
      // }
      // if(node.level == 2){
      //   this.kcfzdw = data.name;
      //   this.xiId = data.parentId;
      //   this.jysId = data.id;
      // }
      this.kcfzdw = data.name;
      this.xiId = data.id;
      this.showUnitTree = false;
    },
    // 表格数据选中
    handleSelectionChange(val) {
      this.selectPlanList = val;
    },
    // 下发核对
    async xfhd() {
      if (this.selectPlanList.length > 0) {
        var data = [];
        this.selectPlanList.forEach((item) => {
          let par = {
            id: item.id,
            jcid: item.jc,
            courseId: item.kcid,
            kcbh: item.kcbh,
            grade: item.nj,
            fillBy: this.userInfo.content.user_id,
            xueqi: item.xueqi,
          };
          data.push(par);
        });
        const res = await bpksj_query_edu_sh(data);
        if (res.data.code == 200) {
          this.$message.warning("任务已下发!");
          this.shjxQueryList();
        }
      } else {
        this.$message.warning("请先选择您要下发的任务!");
        return;
      }
    },
    // 发布
    async fabu() {
      if (this.selectPlanList.length > 0) {
        var data = [];
        this.selectPlanList.forEach((item) => {
          let par = {
            id: item.id,
            jcid: item.jc,
            courseId: item.kcid,
            fillBy: this.userInfo.content.user_id,
          };
          data.push(par);
        });
        const res = await jxbgl_data_fb(data);
        if (res.data.code == 200) {
          this.$message.warning("任务已下发!");
          this.shjxQueryList();
        }
      } else {
        this.$message.warning("请先选择您要下发的任务!");
        return;
      }
    },
    // 审核通过
    async shtg() {
      if (this.selectPlanList.length > 0) {
        var data = [];
        let flag = false;
        let flag_fb = false;
        let flag_fzr = false;
        let arr = [];
        let newClassId = [];
        this.selectPlanList.forEach((item) => {
          arr = arr.concat(item.jxbList);
          if(item.state == '审核通过'){
            flag = true;
          }
          if(item.state == '已发布'){
            flag_fb = true;
          }
          if(item.courseCharger == ''){
            flag_fzr = true;
          }
          let par = {
            id: item.id,
            jcid: item.jc,
            courseId: item.kcid,
            fillBy: this.userInfo.content.user_id,
          };
          data.push(par);
        });
        
        if(flag){
          this.$message.warning('所选数据中已包含审核通过项，请勿重复审核!');
          return
        }

        if(flag_fb){
          this.$message.warning('所选数据中已包含已发布项，无法进行审核!');
          return
        }
        if(flag_fzr){
          this.$message.error('所选数据中尚未有课程负责人信息，无法进行审核!');
          return
        }
        
        arr.filter(res=>{
          newClassId.push(res.id)
        })
        let classIds = newClassId.join(',')
        createDataForCourse(this.selectPlanList).then(res => {
          if (res.data.code === 200) {
            bpksj_query_edu_tg(data,classIds).then(res1 => {
              if (res1.data.code === 200) {
                this.$message.warning("审核已通过!");
                this.shjxQueryList();
              }
            })
          } else {
            this.$message.warning('同步课程考核数据失败！')
          }
        })
      } else {
        this.$message.warning("请先选择您要审核的任务!");
        return;
      }
    },
    // 获取审核状态
    async queryCommonShzt() {
      const res = await queryCommonShzt();
      if (res.data.code == 200) {
        this.ztList = res.data.data;
      }
    },
    // 获取培养层次列表
    async queryCommonPycc() {
      const res = await queryCommonPyccId();
      if (res.data.code == 200) {
        this.pyccList = res.data.data;
      }
    },
    // 获取年级列表
    async queryCommonNj() {
      const res = await queryCommonNj("");
      if (res.data.code == 200) {
        this.jcList = res.data.data;
      }
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.xqList = res.data.data;
      }
    },
    // 查看最后修改人信息
    viewLastEdit(row) {
      this.$router.push({
        path: "/admin/teachingTaskManage/teachingclass/LastModified",
        query: {
          id: row.fillby,
        },
      });
    },
    taskBack() {
      if (this.selectPlanList.length > 0) {
        this.taskBackDialog = true;
      }  else {
        this.$message.warning("请先选择您要打回的任务!");
        return;
      }
    },
    // 打回
    async submitTaskBack() {
      if (this.backReason == "" || this.backReason == null) {
        this.$message.warning("请先填写打回原因!");
        return;
      }
      var data = [];
      let flag_fb =false;
        this.selectPlanList.forEach((item) => {
          if(item.state == '已发布'){
            flag_fb = true;
          }
          let par = {
            id: item.id,
            jcid: item.jc,
            courseId: item.kcid,
            kcbh: item.kcbh,
            grade: item.nj,
            fillBy: this.userInfo.content.user_id,
            reason: this.backReason,
            xueqi: item.xueqi,
          };
          data.push(par);
        });
        if(flag_fb){
          this.$message.warning('所选数据中已包含已发布项，无法进行打回!');
          return
        }
      // var params = {
      //   fillBy: this.userInfo.content.user_id,// 当前登陆人
      //   id: "",
      //   jcid: "", //
      // };
      const res = await jxbgl_data_dh(data);
      if (res.data.code == 200) {
        this.$message.success("任务打回成功!");
        this.cancelTaskBack();
        this.shjxQueryList();
      }
    },
    cancelTaskBack() {
      this.backReason = "";
      this.taskBackDialog = false;
    },
    // 打开备注弹窗
    addRemarks(row) {
      this.selectRow = row;
      this.remarksDialog = true;
    },
    // 备注提交
    async submitRemarks() {
      if (this.remarks_fill == "" || this.remarks_fill == null) {
        this.$message.warning("请先填写备注信息!");
        return;
      }
      console.log('-----------------------', this.selectRow)
      var params = {
        fillBy: this.userInfo.content.user_id, // 当前登陆人
        courseId: this.selectRow.kcid,
        kcbh: this.selectRow.kcbh,
        id: this.selectRow.id,
        grade: this.selectRow.nj,
        xueqi: this.selectRow.xueqi,
        remark: this.remarks_fill,
      };
      const res = await jxbgl_data_remark(params);
      if (res.data.code == 200) {
        this.$message.success("提交成功!");
        this.cancelRemarkDialog();
        this.shjxQueryList();
      }
    },
    // 关闭弹窗
    cancelRemarkDialog() {
      this.remarks_fill = "";
      this.remarksDialog = false;
    },
    async shjxQueryList() {
      var term = this.xq;
      var xb = this.xiId;
      var courseName = this.kcmc;
      var pyLevel = this.pycc;
      var nj = this.jc;
      var status = this.zt;
      var fzdw = '';
      var current = this.currentPage;
      var size = this.pageSize;
      const res = await shjx_query_list(term, xb, courseName, pyLevel, nj, status, current, size);
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(this.pageSize, res.data.data.current, length);
      }
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage) + parseInt(length) - 1;
      }
    },
    editBtn() {
      this.$router.push("/admin/teachingTaskManage/profCourse");
    },
    planImport() {
      this.$router.push("/admin/teachingTaskManage/planImport");
    },
    tipConfirm() {},
    syncShow() {
      this.syncShowTip = true;
    },
    addHours() {
      this.$router.push("/teacher/workload/ClassTimeQuery");
    },
    showDetailBtn(row, data) {
      // this.selectId = row.id;
      this.rowTitle = data.name + "(" + data.yxrs + ")";
      this.showDetailDialog = true;
      this.querySkbcStudent(row, data.id);
    },
    // 查询上课班次人员列表
    async querySkbcStudent(row, id) {
      // var _this = this;
      var courseNo = row.kcbh;
      var nj = '';
      var zybcId = id;
      var xueqi = row.xueqi;
      const res = await jxbgl_query_student_list(courseNo, nj, zybcId, xueqi);
      if (res.data.code == 200) {
        var data = res.data.data;
        this.tableData2 = [];
        data.forEach((item) => {
          item.birthday = item.birthday.substring(0, 10);
          this.tableData2.push(item);
        });
        // this.personSelect = []
        // setTimeout(() => {
        //   var select = this.selectList.filter((item) => item.id == id);
        //   if (select.length > 0) {
        //     this.personSelect = select[0].select;
        //
        //     select[0].select.forEach((it) => {
        //       this.tableData2.find(item => {
        //         if (it.id == item.id) {
        //           this.$refs.multipleTable.toggleRowSelection(item, true)
        //         }
        //       })
        //     })
        //   }
        // }, 100);
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../../../../styles/text.less";
// 表格底部样式
@import "../../../../../styles/delayedExam.less";

@import "../../../../../styles/supervision.less";

.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.assessment-container {
  width: 1803px;
  margin: 0 auto;
  .search-container {
    margin-top: 27px;
    padding-left: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    .search-container-left,
    .search-container-right {
      margin-top: 0px;
      display: flex;
      flex-direction: row;
    }
    .search-container-item {
      color: #004ca7;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      margin-right: 30px;
      > span {
        margin-right: 6px;
      }
    }
    .search-button {
      width: 77px;
      height: 28px;
      line-height: 28px;
      background: #f1f8fe;
      border: 1px solid #51aef6;
      border-radius: 6px;
      cursor: pointer;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      > span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #51aef6;
      }
      > img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }
    }
  }
  // .bottom-block-export {
  //   right: 0;
  //   width: 127px;
  //   height: 27px;
  //   line-height: 34px;
  //   background: #fff6ef;
  //   border: 1px solid #f3b815;
  //   opacity: 1;
  //   border-radius: 6px;
  //   cursor: pointer;
  //   display: flex;
  //   flex-direction: row;
  //   align-items: center;
  //   justify-content: center;
  //   margin-top: 10px;
  //   > span {
  //     font-size: 16px;
  //     font-family: Source Han Sans CN;
  //     font-weight: 500;
  //     color: #f3b815;
  //   }
  //   > img {
  //     width: 16px;
  //     height: 16px;
  //     margin-right: 9px;
  //   }
  // }
  .class-tip {
    color: #004ca7;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin: 40px;
  }
  .plan-entry-table-container {
    margin-top: 30px;
    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      border-radius: 9px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}

.remarks {
  /deep/ .el-dialog {
    height: 350px;
  }
}

.export-button {
  cursor: pointer;
  width: 127px;
  height: 27px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  > img {
    width: 17px;
    height: 17px;
  }
  > span {
    margin-left: 12px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #f3b815;
  }
}

.bottom-block {
  width: calc(100% - 20px);
  margin: 0 auto;
}

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
    width: 100%;
  }
}

/deep/ .el-tree-node {
  color: #004ca7;
}

.selectTree {
  /deep/ .el-input__inner {
    height: 28px;
  }
}

.undeLine {
  text-decoration: underline;
  cursor: pointer;
}
</style>

<style lang="less" scoped>
  #check-teaching-task-index{
    /deep/ .el-button--warning.is-plain{
      background: #FFF6EF;
      border-color: #F3B815;
      color: #F3B815;
      border-radius: 6px;
    }
    /deep/ .el-button--warning.is-plain:focus, .el-button--warning.is-plain:hover{
      color: #F3B815;
      background: #FFF6EF;
      border: 1px solid #F3B815;
      border-radius: 6px;
    }

    /deep/ .el-button--success.is-plain{
      background: #F1FFF8;
      border-color: #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }
    /deep/ .el-button--success.is-plain:hover{
      background: #F1FFF8;
      border: 1px solid #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }

    /deep/ .el-button--primary.is-plain{
      background: #F1F8FE;
      border-color: #51AEF6;
      color: #51AEF6;
      border-radius: 6px;
    }

    /deep/ .el-button--primary.is-plain:hover{
      background: #F1F8FE;
      border: 1px solid #51AEF6;
      color: #51AEF6;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain{
      background: #FFEFEF;
      border-color: #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain:hover{
      background: #FFEFEF;
      border: 1px solid #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }
  }
</style>
